package collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

public class CollectionsDemo {
	@Test
	public void test() {
		// 开辟16个元素空间
		List<String> list = new ArrayList<>();
		Set<String> set = new HashSet<>();
		// 1.往集合中添加所有元素
		Collections.addAll(list, "def","www","haha","hehe","hoho","haha");
		System.out.println(list);
		// 2.排序, 从小到大
		Collections.sort(list);
		System.out.println(list);
		// 自定义排序规则
		Collections.sort(list, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return o2.compareTo(o1);
			}
		});
		System.out.println(list);
		// 3. 交换list的下标
		Collections.swap(list,0, 1);
		System.out.println(list);
		// 4. 逆序
		Collections.reverse(list);
		System.out.println(list);
		// 5. 洗牌乱序
		Collections.shuffle(list);
		System.out.println(list);
		// 6. !!!!好使用，返回一堆空列表，集合，Map
		List<Object> emptyList = Collections.emptyList();
		Set<Object> emptySet = Collections.emptySet();
		Map<Object, Object> emptyMap = Collections.emptyMap();
	}
}















